﻿
namespace EasyNet.FastDFS
{
    using System.IO;
    using Xunit;

    public class StorageClientTest
    {
        [Fact]
        public void UploadLocalFile()
        {
            var fileInfo = new FileInfo("d:\\1.jpg");
            var storageServer = TrackerClient.GetInstance().GetStoreStorage();
            var result = StorageClient.GetInstance().Upload(storageServer, fileInfo.FullName, null);

            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Equal<int>(2, result.Length);
        }

        [Fact]
        public void UploadSlaveLocalFile()
        {
            var fileInfo = new FileInfo("d:\\1.jpg");
            var storageServer = TrackerClient.GetInstance().GetFetchStorage("gpa", "gpa/M00/00/00/wKgBHk574-XtwUjNAAGN9jfvmqk93..jpg");
            var result = StorageClient.GetInstance().Upload(storageServer, "gpa", "M00/00/00/wKgBHk574-XtwUjNAAGN9jfvmqk93..jpg", "_200x200", fileInfo.FullName, null);

            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Equal<int>(2, result.Length);
        }

        [Fact]
        public void DownloadFile()
        {
            using (var fileStream = new FileStream("d:\\2.jpg", FileMode.Create, FileAccess.Write))
            {
                var storageServer = TrackerClient.GetInstance().GetFetchStorage("gpa", "gpa/M00/00/00/wKgBH057kvOQ2ARuADFvjVTRy8g344_200x100.JPG");
                var result = StorageClient.GetInstance().Download(storageServer, "gpa", "M00/00/00/wKgBH057kvOQ2ARuADFvjVTRy8g344_200x100.JPG", 0, 0, new DownloadStream(fileStream));
                Assert.Equal<int>(0, result);
            }
        }
    }
}
